//
//  Test15.cpp
//  CPPTest
//
//  Created by you5 Yi on 2021/9/15.
//

#include "Test15.hpp"
#include <string>
#define Max 100
class Bank {
    int top;
    char date[Max][10];// 日期
    int money[Max];// 金额
    int rest[Max];// 余额
    int sum;// 累计余额
public:
    Bank() {
        top=0;
    }
    void bankin(char d[], int m) {
        strcpy(date[top],d);
        money[top] = m;
        sum = sum+m;
        rest[top] = sum;
        top++;
    }
    void bankout(char d[], int m) {
        strcpy(date[top], d);
        money[top] = m;
        sum = sum-m;
        rest[top] = sum;
        top++;
        printf("日期存入 取出余额\n");
    }
    void disp() {
        int i;
        for (i=0; i<top; i++) {
            printf("%8s",date[i]);
            if (money[i]<0)
                printf(" %6d",-money[i]);
            else
                printf(" %6d",money[i]);
            printf(" %6d\n",rest[i]);
        }
    }
};

void test15() {
    Bank b;
    b.bankin("2021-09-30", 100);
    b.bankout("2021-09-30", 88);
    b.bankout("2021-09-30", 1);
    b.bankout("2021-09-30", 2);
    b.bankin("2021-10-01", 199);
    b.disp();
}
